package br.com.siscov.model.login.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import br.com.siscov.model.conexao.ConnectionFactory;
import br.com.siscov.model.vo.LoginVo;

public class LoginDAO implements LoginInterfaceDAO{
	private Connection con = null;
	private Statement st = null;
	private ResultSet rs = null;
	PreparedStatement preparedStatement = null;
	
	public LoginDAO()throws Exception{
		con = ConnectionFactory.getConexao();
		st = con.createStatement();

	}
	public void excluirLogin(String login) throws Exception {
		st.executeUpdate("delete from LoginVo where"+login);
		
	}

	public void incluirLogin(LoginVo loginVo) throws Exception {
		st.executeUpdate("insert into LoginVo values('"+loginVo.getLogin()+"','"+loginVo.getSenha()+"')");
		
	}
	public boolean autenticaUsuario(LoginVo loginVo) throws Exception {
		String sql ="select usuario from LoginVo where usuario=? and senha=?";
		
		boolean i = false;
		
		preparedStatement = con.prepareStatement(sql);
		preparedStatement.setString(1, loginVo.getLogin());
		preparedStatement.setString(2, loginVo.getSenha());
		rs = preparedStatement.executeQuery();

	
		try {		
			
			if (rs.next()) {
				i = true;
			}
		} catch (SQLException sqle) {
			throw new Exception(sqle);
		}
		return i;
	}


}
